import React, {Component} from 'react';
import {View} from 'react-native';
import EasyToast from 'react-native-easy-toast';

let toastTop;
let toastCenter;
let toastBottom;

let setState;

// 单例 Toast
export default class GlobalToast extends Component {
    
    constructor(...args) {  
        super(...args);
        this.state = {}
    }
    
    render() {
    	return (
    		<View style={{flex: 1}}>
    			{this.props.children}
    			<EasyToast ref='toastTop' position='top' fadeInDuration={0} fadeOutDuration={800} />
    			<EasyToast ref='toastCenter' position='center' fadeInDuration={0} fadeOutDuration={800} />
    			<EasyToast ref='toastBottom' position='bottom' fadeInDuration={0} fadeOutDuration={800} />
    		</View>
    	);
    }
    
    componentDidMount() {
    	setState = this.setState;
    	toastTop = this.refs.toastTop;
    	toastCenter = this.refs.toastCenter;
    	toastBottom = this.refs.toastBottom;
    }
    
}

export function toast(position) {
	switch (position){
		case 'top':
			return toastTop;
		case 'center':
			return toastCenter;
		case 'bottom':
			return toastBottom;
	}
	return toastBottom;
}
